{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0d685eef",
   "metadata": {},
   "source": [
    "# 第1章 Python基础知识"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1594ca3",
   "metadata": {},
   "source": [
    "# 1.1 Python 概述与环境搭建"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff025199",
   "metadata": {},
   "source": [
    "## 1.1.1 Python 概述"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d6b61be",
   "metadata": {},
   "source": [
    "## 1.1.2 Anaconda 概述"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33ad5bf7",
   "metadata": {},
   "source": [
    "## 1.1.3 Jupyter Notebook 概述"
   ]
  },
  {
   "cell_type": "code",
   "id": "6981cd66",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-17T08:12:23.655167Z",
     "start_time": "2025-08-17T08:12:23.648678Z"
    }
   },
   "source": [
    "print('1')"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "cell_type": "markdown",
   "id": "14c26b1c",
   "metadata": {},
   "source": [
    "## 1.1.4 Python 库的安装"
   ]
  },
  {
   "cell_type": "code",
   "id": "8d837198",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-17T08:12:44.849595Z",
     "start_time": "2025-08-17T08:12:29.652551Z"
    }
   },
   "source": [
    "!pip install seaborn #首次安装后需重启内核，方可生效"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: seaborn in /opt/anaconda3/lib/python3.11/site-packages (0.12.2)\r\n",
      "Requirement already satisfied: numpy!=1.24.0,>=1.17 in /opt/anaconda3/lib/python3.11/site-packages (from seaborn) (1.26.4)\r\n",
      "Requirement already satisfied: pandas>=0.25 in /opt/anaconda3/lib/python3.11/site-packages (from seaborn) (2.1.4)\r\n",
      "Requirement already satisfied: matplotlib!=3.6.1,>=3.1 in /opt/anaconda3/lib/python3.11/site-packages (from seaborn) (3.8.0)\r\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (1.2.0)\r\n",
      "Requirement already satisfied: cycler>=0.10 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (0.11.0)\r\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (4.25.0)\r\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (1.4.4)\r\n",
      "Requirement already satisfied: packaging>=20.0 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (23.1)\r\n",
      "Requirement already satisfied: pillow>=6.2.0 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (10.2.0)\r\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (3.0.9)\r\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /opt/anaconda3/lib/python3.11/site-packages (from matplotlib!=3.6.1,>=3.1->seaborn) (2.8.2)\r\n",
      "Requirement already satisfied: pytz>=2020.1 in /opt/anaconda3/lib/python3.11/site-packages (from pandas>=0.25->seaborn) (2023.3.post1)\r\n",
      "Requirement already satisfied: tzdata>=2022.1 in /opt/anaconda3/lib/python3.11/site-packages (from pandas>=0.25->seaborn) (2023.3)\r\n",
      "Requirement already satisfied: six>=1.5 in /opt/anaconda3/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.1->seaborn) (1.16.0)\r\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "37e1fa62",
   "metadata": {
    "scrolled": false,
    "ExecuteTime": {
     "end_time": "2025-08-17T08:13:08.092564Z",
     "start_time": "2025-08-17T08:12:52.992999Z"
    }
   },
   "source": [
    "! pip install SpeechRecognition -i https://pypi.tuna.tsinghua.edu.cn/simple  #通过清华镜像地址安装 SpeechRecognition 库"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\r\n",
      "Collecting SpeechRecognition\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/aa/cd/4b5f5d04c8a4e25c376858d0ad28c325f079f17c82bf379185abf45e41bf/speechrecognition-3.14.3-py3-none-any.whl (32.9 MB)\r\n",
      "\u001B[2K     \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m32.9/32.9 MB\u001B[0m \u001B[31m6.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\r\n",
      "\u001B[?25hRequirement already satisfied: typing-extensions in /opt/anaconda3/lib/python3.11/site-packages (from SpeechRecognition) (4.9.0)\r\n",
      "Installing collected packages: SpeechRecognition\r\n",
      "Successfully installed SpeechRecognition-3.14.3\r\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "cell_type": "markdown",
   "id": "4ac08962",
   "metadata": {},
   "source": [
    "# 1.2 Python 的数据类型"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca0a7496",
   "metadata": {},
   "source": [
    "## 1.2.1 整型"
   ]
  },
  {
   "cell_type": "code",
   "id": "c6bda63d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-17T08:13:18.711412Z",
     "start_time": "2025-08-17T08:13:18.697337Z"
    }
   },
   "source": [
    "trans = 2 #将整型数值 2 赋值给 trans 变量，代表交易次数\n",
    "type(trans) #查看 trans 变量的数据类型"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "id": "937756a9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-01T02:04:04.550153Z",
     "start_time": "2025-09-01T02:04:04.541613Z"
    }
   },
   "source": [
    "int(2.36)"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 1
  },
  {
   "cell_type": "markdown",
   "id": "ede7ae3b",
   "metadata": {},
   "source": [
    "## 1.2.2 浮点型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0d7f0057",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "332.6\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "200.0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price = 332.6 #将浮点型数值 332.6 赋值给 price 变量，代表价格\n",
    "print(price) #使用 print()函数输出 price 变量值\n",
    "float(200) #将整型数值 200 强制转换为浮点型数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b472cf0f",
   "metadata": {},
   "source": [
    "## 1.2.3 复数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "95486498",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1+2j)\n",
      "(200+0j)\n",
      "(200+3j)\n"
     ]
    }
   ],
   "source": [
    "com = 1+2j #将复数 1+2j 赋值给 com 变量\n",
    "print(com) #使用 print()函数输出 com 变量值\n",
    "print(complex(200)) #将整型数值 200 强制转换为复数，并用 print()函数输出\n",
    "print(complex(200,3)) #将 200 和 3 强制转换为复数，实数部分为 200，虚数部分为 3，并用 print()函数输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40e66d90",
   "metadata": {},
   "source": [
    "## 1.2.4 字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3f647575",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "金融数据分析\n",
      "Python\n",
      "学习\n",
      "什么是字符串\n"
     ]
    }
   ],
   "source": [
    "str1 = '金融数据分析' #用单引号将文本“金融数据分析”赋值给 str1 变量\n",
    "str2 = \"Python\" #用双引号将文本“Python”赋值给 str2 变量\n",
    "str3 = '''学习\n",
    "什么是字符串''' #用 3 个单引号将多行文本赋值给 str3 变量\n",
    "print(str1) #使用 print()函数输出字符串变量 str1\n",
    "print(str2)\n",
    "print(str3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01a5168e",
   "metadata": {},
   "source": [
    "# 1.3 Python 的数据结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90a0d248",
   "metadata": {},
   "source": [
    "## 1.3.1 元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5ff6d5fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stock: AAPL, Price: 150.75, Date: 2023-05-21\n"
     ]
    }
   ],
   "source": [
    "# 创建元组\n",
    "stock_info = ('AAPL', 150.75, '2023-05-21')\n",
    "# 访问元组元素\n",
    "symbol = stock_info[0] #访问元组的第一个元素\n",
    "price = stock_info[1] #访问元组的第二个元素\n",
    "date = stock_info[2] #访问元组的第三个元素\n",
    "print(f'Stock: {symbol}, Price: {price}, Date: {date}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ccc54d07",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('AAPL', 150.75, '2023-05-21', 'NASDAQ')\n",
      "('AAPL', 150.75, '2023-05-21', 'AAPL', 150.75, '2023-05-21')\n",
      "(150.75, '2023-05-21')\n"
     ]
    }
   ],
   "source": [
    "# 元组的连接\n",
    "stock_info_extended = stock_info + ('NASDAQ',)\n",
    "# 元组的重复\n",
    "repeated_info = stock_info * 2\n",
    "# 元组的切片\n",
    "price_date = stock_info[1:3]\n",
    "print(stock_info_extended)\n",
    "print(repeated_info)\n",
    "print(price_date)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82131bff",
   "metadata": {},
   "source": [
    "## 1.3.2 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d4d97916",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First Price: 150.75, Last Price: 148.5\n"
     ]
    }
   ],
   "source": [
    "# 创建列表\n",
    "stock_prices = [150.75, 153.00, 155.25, 148.50]\n",
    "# 访问列表元素\n",
    "first_price = stock_prices[0] #访问列表的第一个元素\n",
    "last_price = stock_prices[-1] #访问列表的最后一个元素\n",
    "print(f'First Price: {first_price}, Last Price: {last_price}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "86d1e1c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[151.0, 155.25, 148.5, 149.75]\n"
     ]
    }
   ],
   "source": [
    "# 添加元素\n",
    "stock_prices.append(149.75)\n",
    "# 删除元素\n",
    "del stock_prices[1]\n",
    "# 修改元素\n",
    "stock_prices[0] = 151.00\n",
    "print(stock_prices)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e35f1319",
   "metadata": {},
   "source": [
    "## 1.3.3 字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4624fefd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stock: AAPL, Price: 150.75\n"
     ]
    }
   ],
   "source": [
    "# 创建字典\n",
    "stock_data = {\n",
    "'symbol': 'AAPL',\n",
    "'price': 150.75,\n",
    "'date': '2023-05-21'\n",
    "}\n",
    "# 访问字典元素\n",
    "symbol = stock_data['symbol']\n",
    "price = stock_data['price']\n",
    "print(f'Stock: {symbol}, Price: {price}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ef203a2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'symbol': 'AAPL', 'price': 151.0, 'exchange': 'NASDAQ'}\n"
     ]
    }
   ],
   "source": [
    "# 添加元素\n",
    "stock_data['exchange'] = 'NASDAQ'\n",
    "# 删除元素\n",
    "del stock_data['date']\n",
    "# 修改元素\n",
    "stock_data['price'] = 151.00\n",
    "print(stock_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "444fa109",
   "metadata": {},
   "source": [
    "# 1.4 Python 的运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "789236c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13 7 30 3.3333333333333335 1 1000 3\n",
      "False True True False True False\n",
      "False True False\n",
      "60 & 13 = 12\n",
      "60 | 13 = 61\n",
      "60 ^ 13 = 49\n",
      "~60 = -61\n",
      "60 << 2 = 240\n",
      "60 >> 2 = 15\n"
     ]
    }
   ],
   "source": [
    "# 算术运算\n",
    "a = 10\n",
    "b = 3\n",
    "print(a + b, a - b, a * b, a / b, a % b, a ** b, a // b)\n",
    "# 比较运算\n",
    "print(a == b, a != b, a > b, a < b, a >= b, a <= b)\n",
    "# 逻辑运算\n",
    "c = True\n",
    "d = False\n",
    "print(c and d, c or d, not c)\n",
    "# 位运算\n",
    "e = 60 # 60 = 0011 1100\n",
    "f = 13 # 13 = 0000 1101\n",
    "result_and = e & f # 12 = 0000 1100 # 按位与\n",
    "print(f'{e} & {f} = {result_and}')\n",
    "result_or = e | f # 61 = 0011 1101 # 按位或\n",
    "print(f'{e} | {f} = {result_or}')\n",
    "result_xor = e ^ f # 49 = 0011 0001 # 按位异或\n",
    "print(f'{e} ^ {f} = {result_xor}')\n",
    "result_not = ~e # -61 = 1100 0011 # 按位取反\n",
    "print(f'~{e} = {result_not}')\n",
    "result_left_shift = e << 2 # 240 = 1111 0000 # 左移\n",
    "print(f'{e} << 2 = {result_left_shift}')\n",
    "result_right_shift = e >> 2 # 15 = 0000 1111 # 右移\n",
    "print(f'{e} >> 2 = {result_right_shift}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f63a24e",
   "metadata": {},
   "source": [
    "# 1.5 Python 的函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ea60223",
   "metadata": {},
   "source": [
    "## 1.5.1 内置函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0acabd2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, Python!\n",
      "4 <class 'float'> 10\n"
     ]
    }
   ],
   "source": [
    "# 使用内置函数\n",
    "print('Hello, Python!') # 输出字符串\n",
    "length = len([1, 2, 3, 4]) # 计算列表长度\n",
    "data_type = type(123.45) # 获取数据类型\n",
    "total = sum([1, 2, 3, 4]) # 计算总和\n",
    "print(length, data_type, total)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b60d9253",
   "metadata": {},
   "source": [
    "## 1.5.2 自定义函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "077f1778",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Profit: 50\n"
     ]
    }
   ],
   "source": [
    "# 定义自定义函数\n",
    "def calculate_profit(cost, revenue): #包含 2 个形参 cost、 revenue\n",
    "    profit = revenue - cost\n",
    "    return profit #自定义函数返回参数 profit\n",
    "# 调用自定义函数\n",
    "cost = 100\n",
    "revenue = 150\n",
    "profit = calculate_profit(cost, revenue) #按顺序传入赋值后的实参 cost、 revenue\n",
    "print(f'Profit: {profit}') #输出传入实参后的返回参数 profit"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bf5e3b8",
   "metadata": {},
   "source": [
    "# 1.6 Python 的基本结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efe6992e",
   "metadata": {},
   "source": [
    "## 1.6.1 顺序结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "d231a977",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Step 1\n",
      "Step 2\n",
      "Step 3\n"
     ]
    }
   ],
   "source": [
    "print('Step 1')\n",
    "print('Step 2')\n",
    "print('Step 3')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9f892e9",
   "metadata": {},
   "source": [
    "## 1.6.2 选择分支结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c3804078",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Price is greater than 100\n"
     ]
    }
   ],
   "source": [
    "price = 150\n",
    "if price > 100:\n",
    "    print('Price is greater than 100')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "686e7c63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Price is 100 or less\n"
     ]
    }
   ],
   "source": [
    "price = 90\n",
    "if price > 100:\n",
    "    print('Price is greater than 100')\n",
    "else:\n",
    "    print ('Price is 100 or less')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "569666f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Price is 100\n"
     ]
    }
   ],
   "source": [
    "price = 100\n",
    "if price > 100:\n",
    "    print('Price is greater than 100')\n",
    "elif price == 100:\n",
    "    print('Price is 100')\n",
    "else:\n",
    "    print('Price is less than 100')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d56e9573",
   "metadata": {},
   "source": [
    "## 1.6.3 循环结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "998d2606",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Price: 150.75\n",
      "Price: 153.0\n",
      "Price: 155.25\n",
      "Price: 148.5\n"
     ]
    }
   ],
   "source": [
    "# for 循环遍历列表\n",
    "stock_prices = [150.75, 153.00, 155.25, 148.50]\n",
    "for price in stock_prices:\n",
    "    print(f'Price: {price}') #依次输出 stock_prices 列表中的 price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e2aa81f4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Count 0\n",
      "Count 1\n",
      "Count 2\n",
      "Count 3\n",
      "Count 4\n"
     ]
    }
   ],
   "source": [
    "# while 循环示例\n",
    "count = 0\n",
    "while count < 5:\n",
    "    print(f'Count {count}')\n",
    "    count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "6f95073b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i = 0, j = 0\n",
      "i = 0, j = 1\n",
      "i = 1, j = 0\n",
      "i = 1, j = 1\n",
      "i = 2, j = 0\n",
      "i = 2, j = 1\n"
     ]
    }
   ],
   "source": [
    "# for 嵌套循环示例\n",
    "for i in range(3): #i 的取值为 0、 1、 2\n",
    "    for j in range(2): #j 的取值为 0、 1\n",
    "        print(f'i = {i}, j = {j}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "65e597cb",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Price: 150.75\n",
      "Price: 155.25\n",
      "Price is too low, stopping the loop.\n",
      "Price: 150.75\n",
      "Price: 155.25\n",
      "Skipping low price.\n",
      "Price: 153.0\n"
     ]
    }
   ],
   "source": [
    "stock_prices = [150.75, 155.25, 148.50, 153.00]\n",
    "# 使用 break 语句\n",
    "for price in stock_prices:\n",
    "    if price < 150:\n",
    "        print ('Price is too low, stopping the loop.')\n",
    "        break #按序遍历列表元素，如果数值小于 150，退出循环\n",
    "    print(f'Price: {price}')\n",
    "    \n",
    "# 使用 continue 语句\n",
    "for price in stock_prices:\n",
    "    if price < 150:\n",
    "        print('Skipping low price.')\n",
    "        continue #按序遍历列表元素，如果数值小于 150，仅跳过本次循环\n",
    "    print(f'Price: {price}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1961a1ff",
   "metadata": {},
   "source": [
    "# 1.7 Python 在金融数据中的应用"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
